package com.leet.code.simple_array;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/30 14:28
 */

public class SortArrayByParityII {
    public static void main(String[] args) {
        Map<Integer,Integer> elements = new HashMap<>();
        elements.keySet(); 
    }
    public int[] sortArrayByParityII(int[] A) {
        int[] B = new int[A.length];    //存放结果的数组
        int a = 0;  //偶数在结果数组的起点索引
        int b = 1;  //奇数在结果数组的起点索引
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 == 0) {    //当A[i]为偶数时,从偶数起点索引开始存放偶数,并且为数组将索引指向下一个偶数存放的位置,下同
                B[a] = A[i];
                a += 2;
            } else {
                B[b] = A[i];
                b += 2;
            }
        }
        return B;
    }
}
